﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.Supervise.Model.Enum;
using System.Data;
using HZ.Supervise.Model.Query;

namespace HZ.Supervise.Web.Hospital
{
    public partial class HosStorage : BasePage
    {
        HZ.Supervise.IBLL.IExecuteContext ih = HZ.Supervise.BLLFactory.ExecuteContext();

        public HosStorage() 
        {
            this.ModuleNo = Module.大型设备监管.ToString();
            this.PageOperateType = OperateType.设备明细查看.ToString();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ddlArea.InitAreaID = CurrentAccount.GetUser().Org.Area.AreaID;
                BindSort();
            }
        }
        private void SetBind()
        {
            int totalCount = 0;
            DataTable dt = ih.GetAllDetailDXSB2(GetQurey(), this.AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out totalCount);
            AspNetPager1.RecordCount = totalCount;
            gvwProduceCatalog.PageSize = AspNetPager1.PageSize;
            gvwProduceCatalog.DataSource = dt;
            gvwProduceCatalog.DataBind();
        }
        //绑定分类名称
        private void BindSort()
        {
            ddlSortName.DataSource = ih.GetSortNameDXSB();
            ddlSortName.DataTextField = "SortName";
            ddlSortName.DataValueField = "SortName";
            ddlSortName.DataBind();
            ddlSortName.Items.Insert(0, new ListItem("全部", ""));
        }
        private QGoodsDXSB GetQurey()
        {
            QGoodsDXSB qd = new QGoodsDXSB();
            qd.OrderDetailState = 1;
            qd.GoodsID = txtGoodsid.Text.Trim();
            qd.ProductName = txtGoodsName.Text.Trim();
            qd.RegCode = txtRegCode.Text.Trim();
            qd.CompanyName_SC = txtProduceCompany_SC.Text.Trim();
            qd.Outlookc = txtOutLook.Text.Trim();
            qd.ProductionArea = txtProductionArea.Text.Trim();
            qd.SaleServices = txtSaleServices.Text.Trim();
            qd.SortName = ddlSortName.SelectedValue;
            qd.OrderName = txtOrderName.Text.Trim();
            qd.CompanyName_JX = txtJXName.Text.Trim();
            qd.HospitalName = txtHosName.Text.Trim();
            qd.AreaID = ddlArea.SelectedAreaID;
            qd.SortFields = "SubmiTime desc,SortName";
            return qd;
        }
        protected void AspNetPager1_OnPageChanged(object sender, EventArgs e)
        {
            SetBind();
        }
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
        }

        protected void btnExport_Click(object sender, EventArgs e)
        {
            int totalCount = 0;
            DataTable dt = ih.GetAllDetailDXSB2(GetQurey(), 1, 0, out totalCount);
            if (dt.Rows.Count > 0)
            {
                ExportFile.Instance.ExportData(dt, gvwProduceCatalog, this);
            }
            else
            {
                HZ.Web.WebUtil.Alert("没有需导出的数据", this.Page);
            }
        }
        protected string SubStr(object obj)
        {
            string substring = "";
            if (obj != null)
            {
                int length = obj.ToString().Length;
                if (length > 20)
                {
                    substring = obj.ToString().Substring(0, 20) + "...";
                }
                else
                {
                    substring = obj.ToString();
                }
            }
            return substring;
        }
    }
}